const fs = require('fs')
const path = require('path')


function preParellDeep(dir) {
    return new Promise((resolve, reject) => {
        fs.stat(dir, function (err, statObj) {
            if (statObj.isFile()) {
                fs.unlink(dir, resolve)
            } else {
                fs.readdir(dir, function (err, dirs) {
                    dirs = dirs.map(item => preParellDeep(path.join(dir, item)))
                    console.log('dirs',dir,dirs)
                    Promise.all(dirs).then(() => {
                        fs.rmdir(dir, resolve)
                    })
                })
            }
        })
    })
}

preParellDeep(path.resolve(__dirname, 'a')).then(res => {
    console.log('删除成功')
})